/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dp1.pucp.Simulacion.VIsta;

import com.dp1.pucp.Util.Validaciones;
import java.awt.event.ActionListener;

/**
 *
 * @author WALTER
 */
public class ParametrosSimulacionGUI extends javax.swing.JPanel {

    /**
     * Creates new form ParametrosSimulacion
     */
    public ParametrosSimulacionGUI() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtIteracionGrasp = new javax.swing.JTextField();
        txtAleatoriedadGrasp = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        txtTemperaturaInicial = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtTemperaturaFinal = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtFactorEnfriamiento = new javax.swing.JTextField();
        btnLimpiar = new javax.swing.JButton();
        btnGuardar = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Configuracion de Parametros de Simulacion", 0, 0, new java.awt.Font("Ubuntu", 0, 15))); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Grasp Inicial"));

        jLabel1.setText("Iteraciones:");

        jLabel2.setText("Factor Aletoriedad:");

        txtIteracionGrasp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtIteracionGraspKeyTyped(evt);
            }
        });

        txtAleatoriedadGrasp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtAleatoriedadGraspKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtAleatoriedadGrasp, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtIteracionGrasp, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtIteracionGrasp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtAleatoriedadGrasp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel2.getAccessibleContext().setAccessibleName("");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Recocido Simulado"));

        jLabel4.setText("Temperatura Inicial:");

        txtTemperaturaInicial.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTemperaturaInicialKeyTyped(evt);
            }
        });

        jLabel5.setText("Temperatura Final:");

        txtTemperaturaFinal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTemperaturaFinalKeyTyped(evt);
            }
        });

        jLabel7.setText("Factor Enfriamiento");

        txtFactorEnfriamiento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtFactorEnfriamientoKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtTemperaturaInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtTemperaturaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtFactorEnfriamiento, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTemperaturaInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtTemperaturaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtFactorEnfriamiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        btnLimpiar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/clear.png"))); // NOI18N
        btnLimpiar.setText("Limpiar");
        btnLimpiar.setBorderPainted(false);
        btnLimpiar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnLimpiar.setMaximumSize(new java.awt.Dimension(57, 29));
        btnLimpiar.setMinimumSize(new java.awt.Dimension(57, 29));
        btnLimpiar.setPreferredSize(new java.awt.Dimension(57, 29));
        btnLimpiar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        btnGuardar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/save.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.setBorderPainted(false);
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGuardar.setMaximumSize(new java.awt.Dimension(57, 29));
        btnGuardar.setMinimumSize(new java.awt.Dimension(57, 29));
        btnGuardar.setPreferredSize(new java.awt.Dimension(57, 29));
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(60, 60, 60))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jPanel1.getAccessibleContext().setAccessibleName("Configuracion Parametros");
    }// </editor-fold>//GEN-END:initComponents

    
    public void mostrarAviso(String msn){
        Validaciones.mostrarMensajeAvisoVal(msn);   
    }
    public void mostrarError(String msn){
        Validaciones.mostrarMensajeErrorVal(msn);           
    }
    private void txtIteracionGraspKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtIteracionGraspKeyTyped
        // TODO add your handling code here:
        String car = txtIteracionGrasp.getText();
        if(car.length()>=9) evt.consume();        
        Validaciones.soloDigito(evt);
    }//GEN-LAST:event_txtIteracionGraspKeyTyped

    private void txtAleatoriedadGraspKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtAleatoriedadGraspKeyTyped
        // TODO add your handling code here:
        String car = txtAleatoriedadGrasp.getText();
        if(car.length()>=9) evt.consume();        
        Validaciones.soloReal(evt);
    }//GEN-LAST:event_txtAleatoriedadGraspKeyTyped

    private void txtTemperaturaInicialKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTemperaturaInicialKeyTyped
        // TODO add your handling code here:
        String car = txtTemperaturaInicial.getText();
        if(car.length()>=9) evt.consume();        
        Validaciones.soloReal(evt);
    }//GEN-LAST:event_txtTemperaturaInicialKeyTyped

    private void txtTemperaturaFinalKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTemperaturaFinalKeyTyped
        // TODO add your handling code here:
        String car = txtTemperaturaFinal.getText();
        if(car.length()>=9) evt.consume();        
        Validaciones.soloReal(evt);
    }//GEN-LAST:event_txtTemperaturaFinalKeyTyped

    private void txtFactorEnfriamientoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFactorEnfriamientoKeyTyped
        // TODO add your handling code here:
        String car = txtFactorEnfriamiento.getText();
        if(car.length()>=9) evt.consume();        
        Validaciones.soloReal(evt);
    }//GEN-LAST:event_txtFactorEnfriamientoKeyTyped

    
    public void addGuardarListener(ActionListener ml){ this.btnGuardar.addActionListener(ml); }
    public void addLimpiarListener(ActionListener ml){ this.btnLimpiar.addActionListener(ml); }
   
    public double getAleatoriedadGrasp(){  
        String res;
        if (txtAleatoriedadGrasp.getText()==null || (Validaciones.isNumeric(txtAleatoriedadGrasp.getText()))) {
            res="0.0";
        }
        else {
            res=txtAleatoriedadGrasp.getText();
        }
        //return Double.parseDouble(txtAleatoriedadGrasp.getText()); 
        return Double.parseDouble(res);
    }
    
    public double getFactorEnfriamiento(){
        String res;
        if (txtFactorEnfriamiento.getText()==null || (Validaciones.isNumeric(txtAleatoriedadGrasp.getText()))) {
            res="0.0";
        }
        else {
            res=txtFactorEnfriamiento.getText();
        }
        return Double.parseDouble(txtFactorEnfriamiento.getText());
    }
    
    public int getIteracionGrasp(){
        String res;
        if (txtIteracionGrasp.getText()==null) {
            res="0";
        }
        else {
            res=txtIteracionGrasp.getText();
        }
        return Integer.parseInt(txtIteracionGrasp.getText());
    }
    
    public int getIteracionRecocido(){
        return Integer.parseInt(txtIteracionGrasp.getText());
    }
    
    public double getTemperaturaFinal(){
        String res;
        if (txtTemperaturaFinal.getText()==null || (Validaciones.isNumeric(txtAleatoriedadGrasp.getText()))) {
            res="0.0";
        }
        else {
            res=txtTemperaturaFinal.getText();
        }
        return Double.parseDouble(txtTemperaturaFinal.getText());
    }
    
    public double getTemperaturaInicial(){
        String res;
        if (txtTemperaturaInicial.getText()==null || (Validaciones.isNumeric(txtAleatoriedadGrasp.getText()))) {
            res="0.0";
        }
        else {
            res=txtTemperaturaInicial.getText();
        }
        return Double.parseDouble(txtTemperaturaInicial.getText());
    }
    
    public void limpiarDatos(){
        txtAleatoriedadGrasp.setText("");
        txtFactorEnfriamiento.setText("");
        txtIteracionGrasp.setText("");
        txtTemperaturaFinal.setText("");
        txtTemperaturaInicial.setText("");
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField txtAleatoriedadGrasp;
    private javax.swing.JTextField txtFactorEnfriamiento;
    private javax.swing.JTextField txtIteracionGrasp;
    private javax.swing.JTextField txtTemperaturaFinal;
    private javax.swing.JTextField txtTemperaturaInicial;
    // End of variables declaration//GEN-END:variables
}
